package org.aspectsense.middleware.monitor;

import java.io.Serializable;
import java.util.EventObject;

import org.osgi.framework.ServiceReference;

/**
 * Abstracts an OSGi Service Event. 
 * It is a wrapper class that contains any necessary information 
 * for a generated OSGi event, such as service REGISTERED or UNREGISTERED.
 * 
 * @author Costas Kakousis
 *
 */
public class OSGiServiceEvent extends EventObject implements Serializable {

	private static final long serialVersionUID = 1L;
	private Object serviceProviderObject;
	private ServiceReference serviceReference;
	private String bundleName;
	private Action action;
	
	public static enum Action {REGISTERED, UNREGISTERED}

	public OSGiServiceEvent(final Object serviceProviderObject , ServiceReference serviceReference, Action a) {
		super(serviceProviderObject);
		this.serviceProviderObject = serviceProviderObject;
		this.serviceReference = serviceReference;
		this.bundleName = serviceReference.getBundle().getSymbolicName();
		this.action = a;
		
	}
	
	public Object getServiceProvider (){
		return this.serviceProviderObject;
	}
	public Class<? extends Object> getServiceProviderClass (){
		return this.serviceProviderObject.getClass();
	}
	public ServiceReference getServiceReference (){
		return this.serviceReference;
	}
	public String getBundleName(){
		return this.bundleName;
	}
	public Action getAction(){
		return this.action;
	}

}
